package com.yundong.gongchengji.ui.fabaohall.acitivity;

import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.yundong.gongchengji.R;
import com.yundong.gongchengji.base.BaseActivity;
import com.yundong.gongchengji.views.WheelView;

import java.util.Arrays;

/**
 * 发包大厅
 * Created by ls on 2017/2/21.
 */

public class FabaoHallActivity extends BaseActivity implements View.OnClickListener {
    private View title1;
    private TextView textDa1;
    private View title2;
    private View title3;
    private View title4;
    private View title5;
    private View title6;
    private View title8;

    private static final String[] PLANETS = new String[]{"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Uranus", "Neptune", "Pluto"};
    @Override
    public int getContentViewId() {
        return R.layout.activity_fabao_hall;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        setLeft();
        setTitle("发包大厅");
        setRight(this,R.mipmap.img_fabaocall);
        title1=findViewById(R.id.list_item1);
        TextView textView1= (TextView) title1.findViewById(R.id.text_title);
        textView1.setText("项目类型");
        title2=findViewById(R.id.list_item2);
        TextView textView2= (TextView) title2.findViewById(R.id.text_title);
        textView2.setText("专业类型");
        title3=findViewById(R.id.list_item3);
        TextView textView3= (TextView) title3.findViewById(R.id.text_title);
        textView3.setText("项目名称");
        title4=findViewById(R.id.list_item4);
        TextView textView4= (TextView) title4.findViewById(R.id.text_title);
        textView4.setText("项目地点");
        title5=findViewById(R.id.list_item5);
        TextView textView5= (TextView) title5.findViewById(R.id.text_title);
        textView5.setText("期望工期");
        title6=findViewById(R.id.list_item6);
        TextView textView6= (TextView) title6.findViewById(R.id.text_title);
        textView6.setText("项目预算");
        title8=findViewById(R.id.list_item8);
        TextView textView8= (TextView) title8.findViewById(R.id.text_title);
        textView8.setText("项目规模");
    }

    @Override
    protected void initVariable() {
        title1.setOnClickListener(this);
        title2.setOnClickListener(this);
        title3.setOnClickListener(this);
    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.textRight:
                showToast(FabaoHallActivity.this,"显示");
                break;
            case R.id.list_item1:
                showPopu();
                break;
            case R.id.list_item2:
                showPopu();
                break;
            case R.id.list_item3:
                showPopu();
                break;
        }
    }
    public void showPopu(){
        View view = LayoutInflater.from(this).inflate(R.layout.pupu_layout, null);
        PopupWindow popupWindow = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        //设置显示消失动画

        lp.alpha = 0.4f;
        getWindow().setAttributes(lp);
        popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp =getWindow().getAttributes();
                lp.alpha = 1.0f;
                getWindow().setAttributes(lp);
            }
        });

        WheelView wv= (WheelView)view.findViewById(R.id.wheel_view_wv);
        wv.setOffset(1);
        wv.setItems(Arrays.asList(PLANETS));
        wv.setSeletion(3);
        wv.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
            @Override
            public void onSelected(int selectedIndex, String item) {
                Log.d("显示", "[Dialog]selectedIndex: " + selectedIndex + ", item: " + item);
            }
        });
    }
}
